<template>
  <div class="main-content">
    <!-- 列表页 -->
    <div v-if="showFlag">
      <el-form :inline="true" :model="searchForm" class="form-content">
        <el-form-item label="用户名">
          <el-input v-model="searchForm.yonghuming"
                    clearable placeholder="用户名"></el-input>
        </el-form-item>
        <el-form-item label="学历">
          <el-input v-model="searchForm.xueli"
                    clearable placeholder="学历"></el-input>
        </el-form-item>
        <el-form-item label="岗位类别">
          <el-input v-model="searchForm.gangweileibie"
                    clearable placeholder="岗位类别"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button round @click="search()">查询</el-button>
          <el-button
              v-if="isAuth('qiuzhizhexinxi','新增')"
              round
              type="primary"
              @click="addOrUpdateHandler()"
          >新增
          </el-button>
          <el-button
              v-if="isAuth('qiuzhizhexinxi','删除')"
              :disabled="dataListSelections.length <= 0"
              round
              type="danger"
              @click="deleteHandler()"
          >删除
          </el-button>
        </el-form-item>
      </el-form>
      <div class="table-content">
        <el-table
            v-if="isAuth('qiuzhizhexinxi','查看')"
            v-loading="dataListLoading"
            :data="dataList"
            border
            style="width: 100%;"
            @selection-change="selectionChangeHandler">
          <el-table-column
              align="center"
              header-align="center"
              type="selection"
              width="50">
          </el-table-column>
          <el-table-column
              align="center"
              header-align="center"
              label="用户名"
              prop="yonghuming"
              sortable>
            <template slot-scope="scope">
              {{ scope.row.yonghuming }}
            </template>
          </el-table-column>
          <el-table-column
              align="center"
              header-align="center"
              label="姓名"
              prop="xingming"
              sortable>
            <template slot-scope="scope">
              {{ scope.row.xingming }}
            </template>
          </el-table-column>
          <el-table-column
              align="center"
              header-align="center"
              label="性别"
              prop="xingbie"
              sortable>
            <template slot-scope="scope">
              {{ scope.row.xingbie }}
            </template>
          </el-table-column>
          <el-table-column
              align="center"
              header-align="center"
              label="电话"
              prop="dianhua"
              sortable>
            <template slot-scope="scope">
              {{ scope.row.dianhua }}
            </template>
          </el-table-column>
          <el-table-column align="center"
                           header-align="center"
                           label="照片"
                           prop="zhaopian"
                           width="200">
            <template slot-scope="scope">
              <div v-if="scope.row.zhaopian">
                <img :src="scope.row.zhaopian.split(',')[0]" height="100" min-width="100">
              </div>
              <div v-else>无图片</div>
            </template>
          </el-table-column>
          <el-table-column
              align="center"
              header-align="center"
              label="学历"
              prop="xueli"
              sortable>
            <template slot-scope="scope">
              {{ scope.row.xueli }}
            </template>
          </el-table-column>
          <el-table-column
              align="center"
              header-align="center"
              label="岗位类别"
              prop="gangweileibie"
              sortable>
            <template slot-scope="scope">
              {{ scope.row.gangweileibie }}
            </template>
          </el-table-column>
          <el-table-column align="center"
                           header-align="center"
                           label="简历"
                           prop="jianli">
            <template slot-scope="scope">
              <el-button size="small" type="text" @click="download(scope.row.jianli)">下载</el-button>
            </template>
          </el-table-column>
          <el-table-column
              align="center"
              header-align="center"
              label="工作经历"
              prop="gongzuojingli"
              sortable>
            <template slot-scope="scope">
              {{ scope.row.gongzuojingli }}
            </template>
          </el-table-column>
          <el-table-column
              align="center"
              header-align="center"
              label="操作">
            <template slot-scope="scope">
              <el-button v-if="isAuth('qiuzhizhexinxi','查看')" icon="el-icon-edit" size="small" type="text"
                         @click="addOrUpdateHandler(scope.row.id,'info')">详情
              </el-button>
              <el-button v-if="isAuth('qiuzhizhexinxi','修改')" icon="el-icon-edit" size="small" type="text"
                         @click="addOrUpdateHandler(scope.row.id)">修改
              </el-button>
              <el-button v-if="isAuth('qiuzhizhexinxi','删除')" icon="el-icon-delete" size="small" type="text"
                         @click="deleteHandler(scope.row.id)">删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
            :current-page="pageIndex"
            :page-size="pageSize"
            :page-sizes="[10, 20, 50, 100]"
            :total="totalPage"
            class="pagination-content"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
        ></el-pagination>
      </div>
    </div>
    <!-- 添加/修改页面  将父组件的search方法传递给子组件-->
    <add-or-update v-if="addOrUpdateFlag" ref="addOrUpdate" :parent="this"></add-or-update>


  </div>
</template>
<script>
import AddOrUpdate from "./add-or-update";

export default {
  data() {
    return {
      xueliOptions: [],
      gangweileibieOptions: [],
      searchForm: {
        key: ""
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      showFlag: true,
      sfshVisiable: false,
      shForm: {},
      chartVisiable: false,
      addOrUpdateFlag: false,
    };
  },
  mounted() {
    this.init();
    this.getDataList();
  },
  filters: {
    htmlfilter: function (val) {
      return val.replace(/<[^>]*>/g).replace(/undefined/g, '');
    }
  },
  components: {
    AddOrUpdate,
  },
  methods: {
    init() {
      this.$http({
        url: `option/xuelixinxi/xueli`,
        method: "get"
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.xueliOptions = data.data;
        } else {
          this.$message.error(data.msg);
        }
      });
      this.$http({
        url: `option/gangweifenlei/gangweileibie`,
        method: "get"
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.gangweileibieOptions = data.data;
        } else {
          this.$message.error(data.msg);
        }
      });
    },
    search() {
      this.pageIndex = 1;
      this.getDataList();
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      let params = {
        page: this.pageIndex,
        limit: this.pageSize,
        sort: 'id',
      }
      if (this.searchForm.yonghuming != '' && this.searchForm.yonghuming != undefined) {
        params['yonghuming'] = '%' + this.searchForm.yonghuming + '%'
      }
      if (this.searchForm.xueli != '' && this.searchForm.xueli != undefined) {
        params['xueli'] = '%' + this.searchForm.xueli + '%'
      }
      if (this.searchForm.gangweileibie != '' && this.searchForm.gangweileibie != undefined) {
        params['gangweileibie'] = '%' + this.searchForm.gangweileibie + '%'
      }
      this.$http({
        url: "qiuzhizhexinxi/page",
        method: "get",
        params: params
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandler(val) {
      this.dataListSelections = val;
    },
    // 添加/修改
    addOrUpdateHandler(id, type) {
      this.showFlag = false;
      this.addOrUpdateFlag = true;
      this.crossAddOrUpdateFlag = false;
      if (type != 'info') {
        type = 'else';
      }
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id, type);
      });
    },
    // 下载
    download(file) {
      window.open(`${file}`)
    },
    // 删除
    deleteHandler(id) {
      var ids = id
          ? [Number(id)]
          : this.dataListSelections.map(item => {
            return Number(item.id);
          });
      this.$confirm(`确定进行[${id ? "删除" : "批量删除"}]操作?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.$http({
          url: "qiuzhizhexinxi/delete",
          method: "post",
          data: ids
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 1500,
              onClose: () => {
                this.search();
              }
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      });
    }
  }
};
</script>
<style lang="scss" scoped>
</style>
